<%@ page import="com.actimind.actitime.util.Util,
                 com.actimind.actitime.util.TimeUtils,
                 com.actimind.actitime.calendar.AbstractCalendarForm"%>
<%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<bean:define id="form" scope="session" name="CalendarForm" type="com.actimind.actitime.calendar.CalendarForm"/>
<bean:define id="calPrefs" name="form" type="com.actimind.actitime.beans.CalendarPrefsBean" property="calendarPreferences" />
<html>
<title>Calendar</title>
<link rel="stylesheet" href="<html:rewrite page="/css/calendar_small.css"/>" type="text/css">
 <script language="JavaScript" src="<html:rewrite page="/js/at.js" />"></script>
 <script language="JavaScript" src="<html:rewrite page="/js/calendar.js?r=1" />"></script>
</html>
<body bgcolor="#ffffff" leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginheight="0" marginwidth="0">
   <script language="Javascript">

        var url = '<html:rewrite page="/calendar.do" />';

        function onCalendarChange()
        {
            var s = cal.getCallback();
            window.location.href=url + "?dateStr=" + window.opener.getSelectedValue(document.forms['dateSelector'].year) + '-' + window.opener.getSelectedValue(document.forms['dateSelector'].month) + '-' + cal.getCurrentDay() + "&yearFrom=" + cal.getStartDate().getFullYear() + "&yearTo=" + cal.getEndDate().getFullYear() + "&selectDate=" + s;
        }

        var iDays = new Array(<%=Util.getDateSetAsCSV(calPrefs.getInvertedDays())%>);
        var cal = getPopupCalendar('<%= form.getDateAsString() %>',
                                   '<%= TimeUtils.todayString()%>',
                                   <%=form.getYearFrom()%>,
                                   <%=form.getYearTo()%>,
                                   '<%=form.getSelectDate()%>',
                                   '<%=calPrefs.getCalendarLayout()%>',
                                   iDays);
   </script>
<form name="dateSelector">
<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
    <tr>
        <td align="center" valign="top">
            <table cellspacing="0" cellpadding="2" border="0" style="margin-top: 10px;">
                <tr>
                    <td>
                    <logic:equal property="previousMonthAvailable" value="true" name="form">
                       <a href='<html:rewrite page="/calendar.do" />?dateStr=<%=form.getPreviousMonthAsString()%>&yearFrom=<%=form.getYearFrom()%>&yearTo=<%=form.getYearTo()%>&selectDate=<%=form.getSelectDate()%>'><html:img page="/img/prev.gif" width="15" height="14" border="0" alt="previous month"/></a>
                    </logic:equal>
                    <logic:equal property="previousMonthAvailable" value="false" name="form"><html:img page="/img/pixel.gif" width="15" height="14" /></logic:equal>
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                       <select name="month" onchange="onCalendarChange()" class="calendarMonthsSelector">
                                    <option value="1" <%=(TimeUtils.getMonth(form.getDate())==1) ? "selected" : ""%>>January</option>
                                    <option value="2" <%=(TimeUtils.getMonth(form.getDate())==2) ? "selected" : ""%>>February</option>
                                    <option value="3" <%=(TimeUtils.getMonth(form.getDate())==3) ? "selected" : ""%>>March</option>
                                    <option value="4" <%=(TimeUtils.getMonth(form.getDate())==4) ? "selected" : ""%>>April</option>
                                    <option value="5" <%=(TimeUtils.getMonth(form.getDate())==5) ? "selected" : ""%>>May</option>
                                    <option value="6" <%=(TimeUtils.getMonth(form.getDate())==6) ? "selected" : ""%>>June</option>
                                    <option value="7" <%=(TimeUtils.getMonth(form.getDate())==7) ? "selected" : ""%>>July</option>
                                    <option value="8" <%=(TimeUtils.getMonth(form.getDate())==8) ? "selected" : ""%>>August</option>
                                    <option value="9" <%=(TimeUtils.getMonth(form.getDate())==9) ? "selected" : ""%>>September</option>
                                    <option value="10" <%=(TimeUtils.getMonth(form.getDate())==10) ? "selected" : ""%>>October</option>
                                    <option value="11" <%=(TimeUtils.getMonth(form.getDate())==11) ? "selected" : ""%>>November</option>
                                    <option value="12" <%=(TimeUtils.getMonth(form.getDate())==12) ? "selected" : ""%>>December</option>
                      </select>
                    </td>
                    <td>
                      <select name="year" onchange="onCalendarChange()" class="calendarYearsSelector">
                        <%
                            for(int i = form.getYearFrom(); i <= form.getYearTo(); i++)
                            {
                        %>
                            <option value="<%=i%>" <%=(TimeUtils.getYear(form.getDate())==i) ? "selected" : ""%>><%=i%></option>
                        <%
                            }
                        %>
                      </select>
                    </td>
                    <td>
                     &nbsp;
                    </td>
                    <td>
                    <logic:equal property="nextMonthAvailable" value="true" name="form">
                      <a href='<html:rewrite page="/calendar.do" />?dateStr=<%=form.getNextMonthAsString()%>&yearFrom=<%=form.getYearFrom()%>&yearTo=<%=form.getYearTo()%>&selectDate=<%=form.getSelectDate()%>'><html:img page="/img/next.gif" width="15" height="14" border="0" alt="next month"/></a>
                    </logic:equal>
                    <logic:equal property="nextMonthAvailable" value="false" name="form"><html:img page="/img/pixel.gif" width="15" height="14" /></logic:equal>
                   </td>
                </tr>
                <tr>
                   <td colspan="6"><html:img page="/img/pixel.gif" width="1" height="3"/></td>
                </tr>
                <tr>
                    <td colspan="6">
                        <table cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr>
                                <td>
                                    <table class="calendarTable" cellspacing="1" cellpadding="5" border="0" width="100%">
                                        <tr>
                                           <td class="currentMonthHeader"><%=form.getDateAsString("MMMMMM, yyyy")%></td>
                                        </tr>
                                    </table>
                                </td>
                           </tr>
                           <tr>
                                <td>
                                    <script language="Javascript">
                                        document.write(cal.getCalendarHTML());
                                    </script>
                                </td>
                           </tr>
                        </table>
                    </td>
              </tr>
              <tr>
                     <td colspan="6">
                            <table cellspacing="0" cellpadding="0" border="0">
                                <tr>
                                  <td class="calendarCurrentDay"><html:img page="/img/pixel.gif" width="15" height="15"/></td>
                                  <td><html:img page="/img/pixel.gif" width="5"/></td>
                                    <td class="currentDate">Today: <%=TimeUtils.toString(TimeUtils.today(), "MMMMMM, dd, yyyy")%></td>
                                </tr>
                            </table>
                     </td>
              </tr>
              <tr>
                  <td colspan="6" align="center" nowrap><a class="closeLink" href="javascript:window.close()">Close window</a></td>
              </tr>
              <tr>
                 <td align="center"><html:img page="/img/pixel.gif" width="10"/></td>
              </tr>
      </table>
     </td>
    </tr>
 </table>
</form>
</body>
</html>